/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package colloque.servlets;

import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author James
 */
public class James extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();

        try {
            Query query = session.createQuery("from MotCle");
            List motscles = query.list();
            request.setAttribute("motscles", motscles);
        } catch (Exception e) {
            e.printStackTrace();
        }

        RequestDispatcher distpacher = request.getRequestDispatcher("/jsp/James.jsp");
        distpacher.forward(request, response);
    }
}
